package org.lzy.shop.database.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import org.lzy.shop.database.entity.GoodsSpecEntity

@Dao
interface GoodsSpecDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(spec: GoodsSpecEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(specs: List<GoodsSpecEntity>)

    @Update
    suspend fun update(spec: GoodsSpecEntity)

    @Delete
    suspend fun delete(spec: GoodsSpecEntity)

    @Query("DELETE FROM goods_specs WHERE cartItemId = :cartItemId")
    suspend fun deleteByCartItemId(cartItemId: Int)

    @Query("SELECT * FROM goods_specs WHERE cartItemId = :cartItemId")
    suspend fun getSpecsByCartItemId(cartItemId: Int): List<GoodsSpecEntity>
}